﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Web.Mvc;
using RiderShop.Mobile.Modle;
using Kevin.Shop.Business.Core.Components;
using Kevin.Shop.Business.Products.Components;
using Kevin.Shop.Business.Service.Entity.Products.Enumerations;
using System.Collections.Specialized;
using RiderShop.Mobile.Common.Component;
using Kevin.Shop.Business.Comments.Components;
using RiderShop.Mobile.Modle;
using RiderShop.Mobile.ServiceEntity.Product;
using Kevin.Shop.Business.Service.Entity.SalesManagement.Shipping;
using Kevin.Shop.Business.Core.Components.Responser;
using RiderShop.Mobile.ServiceEntity.MyAccount;
using Kevin.Shop.Business.Service.Entity.Helper;
using RiderShop.Mobile.ServiceEntity;
using RiderShop.Mobile.Modle.MyAccount;

namespace RiderShop.Mobile.Controllers.MyAccount
{
    public partial class MyAccountController : ThemeController
    {
        #region Get User Favorites Product List
        /// <summary>
        /// 得到用户的收藏列表
        /// </summary>
        /// <param name="pageIndex">当前页的索引</param>
        /// <returns>收藏集合</returns>
        [Authorize]
        [HttpGet]
        public ActionResult MyFavorites(int pageIndex = 0)
        {
            MyFavoritesModel myFavoritesModel = new MyFavoritesModel();
            DbQueryResult<List<ProductBasicInfoExtend>> result = myFavoritesModel.GetUserFavorites(pageIndex, WebClientContext.CON_PageSize);
            if (result != null && result.Data.Count > 0)
            {
                myFavoritesModel.FavoritesList = result.Data;

                return View(WebClientContext.Current.SiteTheme, "MyAccount", "MyFavorites", WebClientContext.Current.CacheKeyDefaultMasterPage, myFavoritesModel);
            }
            return View(WebClientContext.Current.SiteTheme, "MyAccount", "MyFavorites", WebClientContext.Current.CacheKeyDefaultMasterPage, myFavoritesModel);
        }

        /// <summary>
        /// 得到我的收藏列表
        /// </summary>
        /// <param name="pageIndex">当前页的索引</param>
        /// <returns>收藏集合</returns>
        [HttpGet]
        public JsonResult MyFavoritesByAjaxRequest(int pageIndex)
        {
            MyFavoritesModel myFavoritesModel = new MyFavoritesModel();
            DbQueryResult<List<ProductBasicInfoExtend>> result = myFavoritesModel.GetUserFavorites(pageIndex, WebClientContext.CON_PageSize);
    
            return Json(result.Data, JsonRequestBehavior.AllowGet);
        }
        #endregion

        #region Cancel Favority
        /// <summary>
        /// 取消对某个商品的关注
        /// </summary>
        /// <param name="productId">商品Id</param>
        /// <returns></returns>
        [Authorize]
        [HttpGet]
        public ActionResult CancelFavority(string productId)
        {
            string url = SiteUrl.FormatUrl("ProductManagement_DeleteProductFavorite", WebClientContext.Current.UserId, productId);
            RestfulHelper.UpdateWithQueryString(url);

            return Redirect("~/MyAccount/MyFavorites");
        }
        #endregion
    }
}
